class NotFoundError extends Error {
  constructor(message) {
    super(message);
    this.status = 404;
    this.name = "NotFoundError";
  }
}

function success(res, data = {}, message = "success") {
  res.status(200).json({
    code: 200,
    msg: message,
    data,
  });
}
//成功并且创建资源
function msgShow(res, data = {}, message = "success") {
  res.status(201).json({
    code: 200,
    msg: message,
    data,
  });
}

function error(res, message = "error", code = 404) {
  res.status(404).json({
    code,
    msg: message,
  });
}

function fail(res, message = "fail", err) {
  logger.error(message + "__" + err);
  res.status(500).json({
    code: 500,
    msg: message,
  });
}

module.exports = {
  NotFoundError,
  success,
  msgShow,
  fail,
  error,
};
